﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FluorineFx;
using System.Data;
using System.Security.Principal;
using System.Collections;
namespace RemoteFlunorineFx
{
    [RemotingService]
    [Description("Customer data service")]
    public class AuthModule
    {
        [DataTableType("Flex.AuthModule")]
        public ArrayList DoCheckLogIn(string loginId, string pwd)
        {
            int ret = 0;
          //  DataSet ds = UserMgr.IsValid_InternalUser_v2(loginId, pwd, ref ret);
            DataSet ds = GetUserInfo(loginId);// AppDBMng.IsValid_InternalUser_v2(loginId, pwd, ref ret);
            //if (ret==0)
            //{
            //    System.Web.HttpContext.Current.Session["userId"] = loginId;
            //}
            ArrayList array = new ArrayList();
            array.Add(ret);
            array.Add(ds);
            return array;
        }
        private static Dictionary<String, DataSet> userCacheDic = new Dictionary<string, DataSet>();
        static object _lock = null;
        public static void CacheUserInfo(string uname, DataSet ds)
        {
            if (_lock == null)
                _lock = new object();
            lock (_lock)
            {
                userCacheDic[uname] = ds;
            }
        }
        public static DataSet GetUserInfo(string uname)
        {
            DataSet ds = new DataSet();
            if (_lock == null)
                _lock = new object();
            lock (_lock)
            {
                if (userCacheDic.TryGetValue(uname, out ds))
                {
                    return ds;
                }
                else
                {
                    return null;
                }
            }
        }
        public int ChangeUserPassword(string loginId, string oldpwd, string newpwd)
        {
            int ret = -1;
            return ret;
        }
        public DataTable GetDicTable()
        {
            return  WebKpiPage.Data.Sysmng.SysmngDB.GetDicTable();
        }
    }
}
